Skip to content

fix(scheduler): preserve label types on ScheduledTask - #729

Open
X6M-Work wants to merge 1 commit into
taskiq-python:masterfrom
X6M-Work:fix-scheduled-task-label-types
Open

X6M-Work wants to merge 1 commit into
taskiq-python:masterfrom
X6M-Work:fix-scheduled-task-label-types

Conversation

@X6M-Work

Copy link
Copy Markdown

Summary

Preserve labels_types on ScheduledTask so non-string labels (int, float, bool, bytes) keep their types when a scheduled task is dispatched by TaskiqScheduler.on_ready().

Root cause

AsyncKicker.schedule_by_cron(), schedule_by_interval(), and schedule_by_time() call _prepare_message(), which serializes label values into strings in message.labels and records their types in message.labels_types. ScheduledTask only kept labels=message.labels and dropped labels_types. When TaskiqScheduler.on_ready() later created a new AsyncKicker with task.labels, every value was re-serialized as LabelType.STR (turning False into the truthy string "False", 5 into "5", and b"hi" into base64 "aGk=").

Solution

  • taskiq/scheduler/scheduled_task/task.py: add optional labels_types: dict[str, int] | None = None to ScheduledTask so stored schedules remain JSON-serializable and backwards-compatible with schedules that omit labels_types.
  • taskiq/kicker.py: pass labels_types=message.labels_types in schedule_by_cron, schedule_by_interval, and schedule_by_time.
  • taskiq/scheduler/scheduler.py: restore typed labels via parse_label() into a new dict before passing them to AsyncKicker in TaskiqScheduler.on_ready() (and copy task.labels when labels_types is None so task.labels is not mutated).
  • tests/scheduler/test_scheduler.py: add regression tests for schedule_by_cron, schedule_by_interval, schedule_by_time (including JSON round-trip) and for ScheduledTask instances without labels_types.

Verification

  • uv run --no-sync pytest tests/test_kicker.py tests/test_task.py tests/test_utils.py tests/middlewares/ tests/brokers/ tests/scheduler/ -q
  • uv run --no-sync ruff check taskiq/kicker.py taskiq/scheduler/scheduler.py taskiq/scheduler/scheduled_task/task.py tests/scheduler/test_scheduler.py
  • uv run --no-sync mypy taskiq/kicker.py taskiq/scheduler/scheduler.py taskiq/scheduler/scheduled_task/task.py tests/scheduler/test_scheduler.py

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.16%. Comparing base (885a19d) to head (d846941).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #729      +/-   ##
==========================================
+ Coverage   86.11%   86.16%   +0.05%     
==========================================
  Files          69       69              
  Lines        2788     2791       +3     
==========================================
+ Hits         2401     2405       +4     
+ Misses        387      386       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant